<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <div class="search-condition-div">
        <el-form-item label="所属行业:" style="height:45px;"  prop="trade">
          <el-col style="height:45px;">
            <treeselect
              :options="optionsMechanism"
              placeholder="请选择行业."
              @select="handleSelect"
              v-model="value"
              :multiple="true"
              :limit="3"
              style="width: 500px;height:50px;margin-top:0px;position:relative;"
            />
          </el-col>
				</el-form-item>
      </div>
      <div class="search-condition-div">
        <el-form-item label="所属区域:">
          <el-select v-model="province"
           placeholder="请选择省"
           @change="changePro"
           class="width-30" style="padding-left:0px;margin-bottom: 5px">
              <el-option v-for="item in addressData"
                        :key="item.code"
                        :label="item.name"
                        :value="item.name">
              </el-option>
          </el-select>
          <el-select v-model="city"
                    placeholder="请选择市"
                    @change="changeCity"
                    class="width-30 margin-left-20" style="padding-left:10px;">
              <el-option v-for="item in cityData"
                        :key="item.code"
                        :label="item.name"
                        :value="item.name">
              </el-option>
          </el-select>
          <el-select multiple collapse-tags  v-model="district"
                    placeholder="请选择区"
                    @change="changeArea"
                    class="width-30 margin-left-20" style="padding-left:10px;">
              <el-option v-for="item in areaData"
                        :key="item.code"
                        :label="item.name"
                        :value="item.name">
              </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div class="search-condition-div">
        <el-form-item label="经营状态:" prop="regStatus">
          <span
            v-for="(item, index) in regStatusData"
            :key="index"
            @click="changeregstatusColor(item,index)"
            :class="'1' === item.checked ? 'active' : ''"
          >
            {{ item.name }}
          </span>
        </el-form-item>
      </div>
      <!-- <div class="search-condition-div">
        <el-form-item label="企业类型:" prop="comType">
          <span
            v-for="(item, index) in comTypeData"
            :key="index"
            @click="changecomtypeColor(item,index)"
            :class="'1' === item.checked ? 'active' : ''"
          >
            {{ item.name }}
          </span>
        </el-form-item>
      </div> -->
      <div class="search-condition-div">
        <el-form-item label="成立年限:" prop="phone">
          <span
            v-for="(item, index) in establishYears"
            :key="index"
            @click="changeestablishYearsColor(item,index)"
            :class="'1' === item.checked ? 'active' : ''"
          >
            {{ item.name }}
          </span>
        </el-form-item>
      </div>
      <!-- <div class="search-condition-div">
        <el-form-item label="联系方式:" prop="telFlag">
          <span
              v-for="(item, index) in telFlagData"
              :key="index"
             @click="changetelFlagColor(item,index)"
              :class="'1' === item.checked ? 'active' : ''"
            >
            {{ item.name }}
          </span>
        </el-form-item>
      </div> -->
      <div class="search-condition-div">
        <el-form-item label="关键联系人:" prop="isKeyPer">
          <span
              v-for="(item, index) in isKeyPerData"
              :key="index"
             @click="changeisKeyPerColor(item,index)"
              :class="'1' === item.checked ? 'active' : ''"
            >
            {{ item.name }}
          </span>
        </el-form-item>
      </div>
      <div class="search-condition-div">
        <el-form-item label="一般纳税人:" prop="taxPayer">
          <span
              v-for="(item, index) in taxPayerData"
              :key="index"
             @click="changetaxPayerColor(item,index)"
              :class="'1' === item.checked ? 'active' : ''"
            >
            {{ item.name }}
          </span>
        </el-form-item>
      </div>
      <div class="search-condition-div">
        <el-form-item label="纳税信用:" prop="taxLevel">
          <span
              v-for="(item, index) in taxLevelData"
              :key="index"
             @click="changetaxLevelColor(item,index)"
              :class="'1' === item.checked ? 'active' : ''"
            >
            {{ item.name }}
          </span>
        </el-form-item>
      </div>
      <div class="search-condition-div">
        <el-form-item label="招投标:" prop="isBid">
          <span
              v-for="(item, index) in isBidData"
              :key="index"
             @click="changeisBidColor(item,index)"
              :class="'1' === item.checked ? 'active' : ''"
            >
            {{ item.name }}
          </span>
        </el-form-item>
      </div>
      <div class="search-condition-div">
        <el-form-item label="高新企业:" prop="isHigh">
          <span
              v-for="(item, index) in isHighData"
              :key="index"
             @click="changeisHighColor(item,index)"
              :class="'1' === item.checked ? 'active' : ''"
            >
            {{ item.name }}
          </span>
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['crm:company:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['crm:company:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['crm:company:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['crm:company:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-connection"
          size="mini"
          @click="chageclue"
          v-hasPermi="['crm:company:chageclue']"
        >转线索</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="companyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="esId" v-if="false"/>
      <el-table-column label="id" align="center" prop="id" v-if="false"/>
      <el-table-column label="企业名称" align="left" prop="comName" width="300" >
        <template slot-scope="scope">
              <a target="_blank" style="color:#007bff;" v-if="scope.row.esId!=null"
                @click="detailReport(scope.row.esId)">
                  {{ scope.row.comName }}
                </a>
            <span v-else>111 {{ scope.row.comName }}</span>
        </template>
      </el-table-column>

      <!-- <template v-for='(col) in columns'>
        <el-table-column
          sortable
          :show-overflow-tooltip="true"
          :prop="col.prop"
          :label="col.label"
          :key="col.prop"
          v-if="col.visible"
          :min-width="col.width" >
        </el-table-column>
      </template> -->


      <el-table-column label="英文名称" align="center" prop="enName"  v-if="false"/>
      <el-table-column label="简称" align="center" prop="shortName"  v-if="false"/>
      <el-table-column label="企业logo" align="center" prop="logo"  v-if="false"/>
      <el-table-column label="联系方式" align="center" prop="linkTel"  v-if="true"/>
      <el-table-column label="经营状态" align="center" prop="regStatus"  width="80"/>
      <el-table-column label="注册资本字符串" align="center" prop="regFundStr"  v-if="false"/>
      <el-table-column label="注册资本数值/万" align="center" prop="regFund"  v-if="false"/>
      <el-table-column label="法人" align="left" prop="regUser" width="80"/>
      <el-table-column label="实际缴纳资本字符串" align="center" prop="actPayStr"  v-if="false"/>
      <el-table-column label="实际缴纳数值" align="center" prop="actPay"  v-if="false"/>
      <el-table-column label="行业" align="center" prop="trade"  v-if="false"/>
      <el-table-column label="成立日期" align="center" prop="regTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.regTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="核准日期" align="center" prop="checkTime" width="80"  v-if="false">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="营业期限" align="center" prop="tradeTime"  v-if="false"/>
      <el-table-column label="企业类型" align="center" prop="comType" v-if="false"/>
      <el-table-column label="所属-省" align="center" prop="province"  v-if="false"/>
      <el-table-column label="所属-市" align="center" prop="city"  v-if="false"/>
      <el-table-column label="区县" align="center" prop="areas"  v-if="false"/>
      <el-table-column label="详细地址" align="center" prop="address" v-if="false" />
      <el-table-column label="统一信用代码" align="left" prop="creditCode" width="200"/>
      <el-table-column label="纳税人识别号" align="center" prop="taxCode"  v-if="false"/>
      <el-table-column label="注册号" align="center" prop="regNo"  v-if="false"/>
      <el-table-column label="组织机构号码" align="center" prop="orgCode"  v-if="false"/>
      <el-table-column label="参保人员" align="center" prop="insured" width="80"/>
      <el-table-column label="曾用名" align="center" prop="beforeName"  v-if="false"/>
      <el-table-column label="最新年报地址" align="center" prop="newReportAd"  v-if="false"/>
      <el-table-column label="注册地址" align="left" prop="regAddre" :show-overflow-tooltip="true"/>
      <el-table-column label="网站" align="center" prop="website"  v-if="false"/>
      <el-table-column label="邮箱" align="center" prop="email"  v-if="false"/>
      <el-table-column label="其他邮箱" align="center" prop="othEmail"  v-if="false"/>
      <el-table-column label="经营范围" align="left" prop="busRange" :show-overflow-tooltip="true"/>
      <el-table-column label="有无疑似关键人" align="center" prop="isKeyPer"  v-if="false"/>
      <el-table-column label="是否为一般纳税人" align="center" prop="taxPayer"  v-if="false"/>
      <el-table-column label="纳税信用" align="center" prop="taxLevel"  v-if="false"/>
      <el-table-column label="招投标" align="center" prop="isBid"  v-if="false"/>
      <el-table-column label="是否高企" align="center" prop="isHigh"  v-if="false"/>
      <el-table-column label="是否年开票800万，年纳税10万以上" align="center" prop="openTax" v-if="false"/>
      <el-table-column label="可用电话" align="center" prop="usableTel" v-if="false"/>
      <el-table-column label="不可用电话" align="center" prop="noAbleTel"  v-if="false"/>
      <el-table-column label="其他联系方式" align="center" prop="othTel"  v-if="false"/>
      <el-table-column label="是否删除：0未删除，1已删除" align="center" prop="isDeleted" v-if="false"/>
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:company:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:company:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业名称" prop="comName">
          <el-input v-model="form.comName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="英文名称" prop="enName">
          <el-input v-model="form.enName" placeholder="请输入英文名称" />
        </el-form-item>
        <el-form-item label="简称" prop="shortName">
          <el-input v-model="form.shortName" placeholder="请输入简称" />
        </el-form-item>
        <el-form-item label="企业logo" prop="logo">
          <el-input v-model="form.logo" placeholder="请输入企业logo" />
        </el-form-item>
        <el-form-item label="联系方式" prop="linkTel">
          <el-input v-model="form.linkTel" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="注册资本字符串" prop="regFundStr">
          <el-input v-model="form.regFundStr" placeholder="请输入注册资本字符串" />
        </el-form-item>
        <el-form-item label="注册资本数值/万" prop="regFund">
          <el-input v-model="form.regFund" placeholder="请输入注册资本数值/万" />
        </el-form-item>
        <el-form-item label="" prop="regUser">
          <el-input v-model="form.regUser" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="实际缴纳资本字符串" prop="actPayStr">
          <el-input v-model="form.actPayStr" placeholder="请输入实际缴纳资本字符串" />
        </el-form-item>
        <el-form-item label="实际缴纳数值" prop="actPay">
          <el-input v-model="form.actPay" placeholder="请输入实际缴纳数值" />
        </el-form-item>
        <el-form-item label="行业" prop="trade">
          <el-input v-model="form.trade" placeholder="请输入行业" />
        </el-form-item>
        <el-form-item label="成立日期" prop="regTime">
          <el-date-picker clearable
            v-model="form.regTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择成立日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="核准日期" prop="checkTime">
          <el-date-picker clearable
            v-model="form.checkTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择核准日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="营业期限" prop="tradeTime">
          <el-input v-model="form.tradeTime" placeholder="请输入营业期限" />
        </el-form-item>
        <el-form-item label="所属-省" prop="province">
          <el-input v-model="form.province" placeholder="请输入所属-省" />
        </el-form-item>
        <el-form-item label="所属-市" prop="city">
          <el-input v-model="form.city" placeholder="请输入所属-市" />
        </el-form-item>
        <el-form-item label="区县" prop="areas">
          <el-input v-model="form.areas" placeholder="请输入区县" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="统一信用代码" prop="creditCode">
          <el-input v-model="form.creditCode" placeholder="请输入统一信用代码" />
        </el-form-item>
        <el-form-item label="纳税人识别号" prop="taxCode">
          <el-input v-model="form.taxCode" placeholder="请输入纳税人识别号" />
        </el-form-item>
        <el-form-item label="注册号" prop="regNo">
          <el-input v-model="form.regNo" placeholder="请输入注册号" />
        </el-form-item>
        <el-form-item label="" prop="orgCode">
          <el-input v-model="form.orgCode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="参保人员" prop="insured">
          <el-input v-model="form.insured" placeholder="请输入参保人员" />
        </el-form-item>
        <el-form-item label="" prop="beforeName">
          <el-input v-model="form.beforeName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="最新年报地址" prop="newReportAd">
          <el-input v-model="form.newReportAd" placeholder="请输入最新年报地址" />
        </el-form-item>
        <el-form-item label="注册地址" prop="regAddre">
          <el-input v-model="form.regAddre" placeholder="请输入注册地址" />
        </el-form-item>
        <el-form-item label="" prop="website">
          <el-input v-model="form.website" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="其他邮箱" prop="othEmail">
          <el-input v-model="form.othEmail" placeholder="请输入其他邮箱" />
        </el-form-item>
        <el-form-item label="经营范围" prop="busRange">
          <el-input v-model="form.busRange" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="有无疑似关键人" prop="isKeyPer">
          <el-input v-model="form.isKeyPer" placeholder="请输入有无疑似关键人" />
        </el-form-item>
        <el-form-item label="是否为一般纳税人" prop="taxPayer">
          <el-input v-model="form.taxPayer" placeholder="请输入是否为一般纳税人" />
        </el-form-item>
        <el-form-item label="纳税信用" prop="taxLevel">
          <el-input v-model="form.taxLevel" placeholder="请输入纳税信用" />
        </el-form-item>
        <el-form-item label="招投标" prop="isBid">
          <el-input v-model="form.isBid" placeholder="请输入招投标" />
        </el-form-item>
        <el-form-item label="是否高企" prop="isHigh">
          <el-input v-model="form.isHigh" placeholder="请输入是否高企" />
        </el-form-item>
        <el-form-item label="是否年开票800万，年纳税10万以上" prop="openTax">
          <el-input v-model="form.openTax" placeholder="请输入是否年开票800万，年纳税10万以上" />
        </el-form-item>
        <el-form-item label="可用电话" prop="usableTel">
          <el-input v-model="form.usableTel" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="不可用电话" prop="noAbleTel">
          <el-input v-model="form.noAbleTel" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="其他联系方式" prop="othTel">
          <el-input v-model="form.othTel" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否删除：0未删除，1已删除" prop="isDeleted">
          <el-input v-model="form.isDeleted" placeholder="请输入是否删除：0未删除，1已删除" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCompany, getCompany, delCompany, addCompany, updateCompany,companychageclue } from "@/api/crm/company";
import jsonData from '@/assets/json/citylist.json'
import industryJsonData from '@/assets/json/industry.json'
import industryJsonData1 from '@/assets/json/industrydata.json'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  components: {
    Treeselect,
  },
  name: "Company",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业信息表格数据
      companyList: [],
      columns: [
          { key: 0, label: `待查询`, visible: true }
        ],
      // 弹出层标题
      title: "",
      followupstatusData: [{"name":"全部","checked":"1"}, {"name":"未处理","checked":"0"}, {"name":"联系方式有效","checked":"0"}, {"name":"联系方式无效","checked":"0"}, {"name":"关闭","checked":"0"}, {"name":"(空白)","checked":"0"}],
      channelData: [{"name":"全部","checked":"1"}, {"name":"无","checked":"0"}, {"name":"微信","checked":"0"}, {"name":"QQ","checked":"0"}, {"name":"微博","checked":"0"}, {"name":"百度","checked":"0"}, {"name":"(空白)","checked":"0"}],
      cluesourcesData: [{"name":"全部","checked":"1"}, {"name":"广告","checked":"0"},{"name":"社交","checked":"0"},{"name":"推广","checked":"0"},{"name":"研讨会","checked":"0"},{"name":"搜索引擎","checked":"0"},{"name":"客户介绍","checked":"0"},{"name":"独立开发","checked":"0"},{"name":"代理商","checked":"0"},{"name":"其他","checked":"0"},{"name":"搜客宝","checked":"0"},{"name":"机器人","checked":"0"},{"name":"访客识别","checked":"0"},{"name":"(空白)","checked":"0"}],
      selectedArray: [],
      regStatusData: [{"name":"全部","checked":"1"},{"name":"存续","checked":"0"},{"name":"迁入","checked":"0"},{"name":"迁出","checked":"0"},{"name":"停业","checked":"0"},{"name":"已歇业","checked":"0"},{"name":"吊销","checked":"0"},{"name":"清算","checked":"0"},{"name":"撤销","checked":"0"},{"name":"注销","checked":"0"},{"name":"(空白)","checked":"0"}],
      comTypeData: [{"name":"全部","checked":"1"},{"name":"有限责任公司","checked":"0"},{"name":"股份有限公司","checked":"0"},{"name":"集体所有制","checked":"0"},{"name":"股份合作公司","checked":"0"},{"name":"国有企业","checked":"0"},{"name":"民营企业","checked":"0"},{"name":"个体工商户","checked":"0"},{"name":"个人独资企业","checked":"0"},{"name":"有限合伙","checked":"0"},{"name":"普通合伙","checked":"0"},{"name":"外商投资企业","checked":"0"},{"name":"港、澳、台商投资","checked":"0"},{"name":"(空白)","checked":"0"}],
      establishYears: [{"name":"不限","checked":"1"},{"name":"1年以内","checked":"0"},{"name":"1-3年","checked":"0"},{"name":"3-5年","checked":"0"},{"name":"5-10年","checked":"0"},{"name":"10年以上","checked":"0"},{"name":"(空白)","checked":"0"}],
      telFlagData: [{"name":"不限","checked":"1"}, {"name":"有","checked":"0"},{"name":"无","checked":"0"},{"name":"(空白)","checked":"0"}],
      isKeyPerData: [{"name":"不限","checked":"1"}, {"name":"有","checked":"0"},{"name":"无","checked":"0"},{"name":"(空白)","checked":"0"}],
      taxPayerData: [{"name":"不限","checked":"1"}, {"name":"是","checked":"0"},{"name":"否","checked":"0"},{"name":"(空白)","checked":"0"}],
      taxLevelData: [{"name":"不限","checked":"1"}, {"name":"A级","checked":"0"},{"name":"非A级","checked":"0"},{"name":"(空白)","checked":"0"}],
      isBidData: [{"name":"不限","checked":"1"}, {"name":"有","checked":"0"},{"name":"无","checked":"0"},{"name":"(空白)","checked":"0"}],
      isHighData: [{"name":"不限","checked":"1"}, {"name":"是","checked":"0"},{"name":"否","checked":"0"},{"name":"(空白)","checked":"0"}],
      industryoptions: this.industryJsonData,
      optionsMechanism: [],
      value: null,
      //  省数据
      addressData: [],
      //  市数据
      cityData: [],
      // 区数据
      areaData: [],
      // 省
      province: '',
      // 市
      city: '',
      // 区
      district: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: [],
        comName: undefined,
        comType: undefined,
        enName: undefined,
        shortName: undefined,
        logo: undefined,
        linkTel: undefined,
        regStatus: undefined,
        regFundStr: undefined,
        regFund: undefined,
        regUser: undefined,
        actPayStr: undefined,
        actPay: undefined,
        trade: undefined,
        regTime: undefined,
        regTimeStr: undefined,
        checkTime: undefined,
        tradeTime: undefined,
        comType: undefined,
        province: undefined,
        city: undefined,
        areas: undefined,
        address: undefined,
        creditCode: undefined,
        taxCode: undefined,
        regNo: undefined,
        orgCode: undefined,
        insured: undefined,
        beforeName: undefined,
        newReportAd: undefined,
        regAddre: undefined,
        website: undefined,
        email: undefined,
        othEmail: undefined,
        busRange: undefined,
        isKeyPer: undefined,
        taxPayer: undefined,
        taxLevel: undefined,
        isBid: undefined,
        isHigh: undefined,
        openTax: undefined,
        usableTel: undefined,
        noAbleTel: undefined,
        othTel: undefined,
        isDeleted: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        esId: [
          { required: true, message: "主键id不能为空", trigger: "blur" }
        ],
        comName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        enName: [
          { required: true, message: "英文名称不能为空", trigger: "blur" }
        ],
        shortName: [
          { required: true, message: "简称不能为空", trigger: "blur" }
        ],
        logo: [
          { required: true, message: "企业logo不能为空", trigger: "blur" }
        ],
        linkTel: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],
        regStatus: [
          { required: true, message: "经营状态不能为空", trigger: "change" }
        ],
        regFundStr: [
          { required: true, message: "注册资本字符串不能为空", trigger: "blur" }
        ],
        regFund: [
          { required: true, message: "注册资本数值/万不能为空", trigger: "blur" }
        ],
        regUser: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        actPayStr: [
          { required: true, message: "实际缴纳资本字符串不能为空", trigger: "blur" }
        ],
        actPay: [
          { required: true, message: "实际缴纳数值不能为空", trigger: "blur" }
        ],
        trade: [
          { required: true, message: "行业不能为空", trigger: "blur" }
        ],
        regTime: [
          { required: true, message: "成立日期不能为空", trigger: "blur" }
        ],
        checkTime: [
          { required: true, message: "核准日期不能为空", trigger: "blur" }
        ],
        tradeTime: [
          { required: true, message: "营业期限不能为空", trigger: "blur" }
        ],
        comType: [
          { required: true, message: "企业类型不能为空", trigger: "change" }
        ],
        province: [
          { required: true, message: "所属-省不能为空", trigger: "blur" }
        ],
        city: [
          { required: true, message: "所属-市不能为空", trigger: "blur" }
        ],
        areas: [
          { required: true, message: "区县不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "详细地址不能为空", trigger: "blur" }
        ],
        creditCode: [
          { required: true, message: "统一信用代码不能为空", trigger: "blur" }
        ],
        taxCode: [
          { required: true, message: "纳税人识别号不能为空", trigger: "blur" }
        ],
        regNo: [
          { required: true, message: "注册号不能为空", trigger: "blur" }
        ],
        orgCode: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        insured: [
          { required: true, message: "参保人员不能为空", trigger: "blur" }
        ],
        beforeName: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        newReportAd: [
          { required: true, message: "最新年报地址不能为空", trigger: "blur" }
        ],
        regAddre: [
          { required: true, message: "注册地址不能为空", trigger: "blur" }
        ],
        website: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        email: [
          { required: true, message: "邮箱不能为空", trigger: "blur" }
        ],
        othEmail: [
          { required: true, message: "其他邮箱不能为空", trigger: "blur" }
        ],
        busRange: [
          { required: true, message: "经营范围不能为空", trigger: "blur" }
        ],
        isKeyPer: [
          { required: true, message: "有无疑似关键人不能为空", trigger: "blur" }
        ],
        taxPayer: [
          { required: true, message: "是否为一般纳税人不能为空", trigger: "blur" }
        ],
        taxLevel: [
          { required: true, message: "纳税信用不能为空", trigger: "blur" }
        ],
        isBid: [
          { required: true, message: "招投标不能为空", trigger: "blur" }
        ],
        isHigh: [
          { required: true, message: "是否高企不能为空", trigger: "blur" }
        ],
        openTax: [
          { required: true, message: "是否年开票800万，年纳税10万以上不能为空", trigger: "blur" }
        ],
        usableTel: [
          { required: true, message: "可用电话不能为空", trigger: "blur" }
        ],
        noAbleTel: [
          { required: true, message: "不可用电话不能为空", trigger: "blur" }
        ],
        othTel: [
          { required: true, message: "其他联系方式不能为空", trigger: "blur" }
        ],
        isDeleted: [
          { required: true, message: "是否删除：0未删除，1已删除不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
        // 省份数据初始化
    this.addressData = jsonData;
    this.industryoptions = industryJsonData;
    this.industrydata = industryJsonData1;
    this.getList();
    this.getData();
  },
  methods: {
    /** 查询企业信息列表 */
    getList() {
      this.loading = true;
      listCompany(this.queryParams).then(response => {
        this.companyList = response.rows;
        this.total = response.total;
        let columns = response.columns;
        if(columns != null){
            this.columns = columns;
        }
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        esId: undefined,
        comName: undefined,
        enName: undefined,
        comType: undefined,
        shortName: undefined,
        logo: undefined,
        linkTel: undefined,
        regStatus: undefined,
        regFundStr: undefined,
        regFund: undefined,
        regUser: undefined,
        actPayStr: undefined,
        actPay: undefined,
        trade: undefined,
        regTime: undefined,
        checkTime: undefined,
        tradeTime: undefined,
        comType: undefined,
        province: undefined,
        city: undefined,
        areas: undefined,
        address: undefined,
        creditCode: undefined,
        taxCode: undefined,
        regNo: undefined,
        orgCode: undefined,
        insured: undefined,
        beforeName: undefined,
        newReportAd: undefined,
        regAddre: undefined,
        website: undefined,
        email: undefined,
        othEmail: undefined,
        busRange: undefined,
        isKeyPer: undefined,
        taxPayer: undefined,
        taxLevel: undefined,
        isBid: undefined,
        isHigh: undefined,
        openTax: undefined,
        usableTel: undefined,
        noAbleTel: undefined,
        othTel: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        isDeleted: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelect(selectedNode) {
      if (selectedNode.children) {
        const childIds = selectedNode.children.map((childNode) => childNode.id);
        const childLables = selectedNode.children.map((childNode) => childNode.label);
        let tradeStr = childLables.join(",");
        this.queryParams.trade = tradeStr;
        this.getList();
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.esId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const esId = row.esId || this.ids
      getCompany(esId).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改企业信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.esId != null) {
            updateCompany(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addCompany(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const esIds = row.esId || this.ids;
      this.$modal.confirm('是否确认删除企业信息编号为"' + esIds + '"的数据项？').then(() => {
        this.loading = true;
        return delCompany(esIds);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    
    /** 导出按钮操作 */
    handleExport() {
      const ids = this.ids;
      if (ids != null) {
        this.queryParams.ids = ids;
      }
      this.download('crm/company/export', {
        ...this.queryParams
      }, `company_${new Date().getTime()}.xlsx`)
    },
    detailReport(companyId) {
      console.log(companyId);
      this.$router.push({ path: '/crm/companydetail/index', query: { companyId: companyId } })
    },
    chageclue() {
      const ids = this.ids;
      if (ids != null) {
        this.queryParams.ids = ids;
      }
      companychageclue(this.queryParams);
      this.getList();
      this.$modal.msgSuccess("操作成功");
    },
    changeregstatusColor(item,index) {
      const fuData = this.regStatusData;
      debugger;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          if (fuData[i].checked == "0") {
            fuData[i].checked = "1";
          } else {
            fuData[i].checked = "0";
          }
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      if (index > 0 && index < newFuData.length) {
        newFuData[0].checked = "0";
      }
      if (index == 0) {
        for (let i = 1; i < newFuData.length; i++) {
          newFuData[i].checked = "0";
        }
        newFuData[0].checked = "1";
      }
      if (index == (newFuData.length - 1)) {
        for (let i = 1; i < newFuData.length; i++) {
          newFuData[i].checked = "0";
        }
        newFuData[0].checked = "1";
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.regStatusData = newFuData;
      this.queryParams.regStatus = searchfollowStatus;
      this.getList();
    },
    changecomtypeColor(item,index) {
      const fuData = this.comTypeData;
      debugger;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          if (fuData[i].checked == "0") {
            fuData[i].checked = "1";
          } else {
            fuData[i].checked = "0";
          }
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      if (index > 0 && index < newFuData.length) {
        newFuData[0].checked = "0";
      }
      if (index == 0) {
        for (let i = 1; i < newFuData.length; i++) {
          newFuData[i].checked = "0";
        }
        newFuData[0].checked = "1";
      }
      if (index == (newFuData.length - 1)) {
        for (let i = 1; i < newFuData.length; i++) {
          newFuData[i].checked = "0";
        }
        newFuData[0].checked = "1";
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.comTypeData = newFuData;
      this.queryParams.comType = searchfollowStatus;
      this.getList();
    },
    //单选
    changeestablishYearsColor(item,index) {
      const fuData = this.establishYears;
      debugger;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          fuData[i].checked = "1";
        } else {
          fuData[i].checked = "0";
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.establishYears = newFuData;
      this.queryParams.regTimeStr = searchfollowStatus;
      this.getList();
    },
    changetelFlagColor(item,index) {
      const fuData = this.telFlagData;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          fuData[i].checked = "1";
        } else {
          fuData[i].checked = "0";
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.telFlagData = newFuData;
      this.queryParams.telFlag = searchfollowStatus;
      this.getList();
    },
    changeisKeyPerColor(item,index) {
      const fuData = this.isKeyPerData;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          fuData[i].checked = "1";
        } else {
          fuData[i].checked = "0";
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.isKeyPerData = newFuData;
      this.queryParams.isKeyPer = searchfollowStatus;
      this.getList();
    },
    changetaxPayerColor(item,index) {
      const fuData = this.taxPayerData;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          fuData[i].checked = "1";
        } else {
          fuData[i].checked = "0";
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.taxPayerData = newFuData;
      this.queryParams.taxPayer = searchfollowStatus;
      this.getList();
    },
    changetaxLevelColor(item,index) {
      const fuData = this.taxLevelData;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          fuData[i].checked = "1";
        } else {
          fuData[i].checked = "0";
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.taxLevelData = newFuData;
      this.queryParams.taxLevel = searchfollowStatus;
      this.getList();
    },
    changeisBidColor(item,index) {
      const fuData = this.isBidData;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          if (fuData[i].checked == "0") {
            fuData[i].checked = "1";
          } else {
            fuData[i].checked = "0";
          }
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      if (index > 0 && index < newFuData.length) {
        newFuData[0].checked = "0";
      }
      if (index == 0) {
        for (let i = 1; i < newFuData.length; i++) {
          newFuData[i].checked = "0";
        }
        newFuData[0].checked = "1";
      }
      if (index == (newFuData.length - 1)) {
        for (let i = 1; i < newFuData.length; i++) {
          newFuData[i].checked = "0";
        }
        newFuData[0].checked = "1";
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.isBidData = newFuData;
      this.queryParams.isBid = searchfollowStatus;
      this.getList();
    },
    changeisHighColor(item,index) {
      const fuData = this.isHighData;
      let newFuData = [];
      let data1 = {};
      let searchfollowStatus = "";
      for (let i = 0; i < fuData.length; i++) {
        if (i == index) {
          fuData[i].checked = "1";
        } else {
          fuData[i].checked = "0";
        }
        data1 = {name:fuData[i].name, checked:fuData[i].checked};
        newFuData.push(data1);
      }
      for (let i = 1; i < newFuData.length; i++) {
          if (newFuData[i].checked == "1") {
            if (searchfollowStatus == "") {
              searchfollowStatus = newFuData[i].name;
            } else {
              searchfollowStatus = searchfollowStatus + "," + newFuData[i].name;
            }
            
          }
      }
      this.isHighData = newFuData;
      this.queryParams.isHigh = searchfollowStatus;
      this.getList();
    },
    // 省份更改
    changePro (e) {
      // 从省中过滤出市的数据
      this.queryParams.province = e;
      this.cityData = this.addressData.filter((item) => {
        console.info(item.children)
        return item.name === e
      })[0].children
      // 省发生改变的时候 清空输入框市区街道的内容
      this.district = ''
      this.city = ''
      // 省发生更改时 该表空区街道数据的内容
      this.areaData = []
      this.getList();
    },
    // 市更改
    changeCity (e) {
      // 获取到区的数据
      this.queryParams.city = e;
      this.areaData = this.cityData.filter((item) => item.name === e)[0].children
      console.info(this.areaData)
      // 清空数据后面对应数组的数据
      this.district = '';
      this.getList();
    },
    // 区更改
    changeArea (e) {
      debugger;
      let area;
      e.forEach(function(element) {
        if (typeof(area) ==  "undefined") {
          area = element;
        } else {
          area = element  + "," + area;
        }
      });
      this.queryParams.areas = area;
      this.getList();
    },
    //将平铺数据转换为树形结构数据
    getTrees(list, parent_id = 0) {
      let parentObj = {};
      list.forEach((o) => {
        parentObj[o.id] = o;
      });
      if (!parent_id) {
        return list
          .filter((o) => !parentObj[o.parent_id])
          .map((o) => ((o.children = this.getTrees(list, o.id)), o));
      } else {
        return list
          .filter((o) => o.parent_id == parent_id)
          .map((o) => ((o.children = this.getTrees(list, o.id)), o));
      }
    },
    //去除转换树形结构数据后存在的空children
    deleteChildren(arr) {
      let childs = arr;
      for (let i = childs.length; i--; i > 0) {
        if (childs[i].children) {
          if (childs[i].children.length) {
            this.deleteChildren(childs[i].children);
          } else {
            delete childs[i].children;
          }
        }
      }
      return arr;
    },
    getData() {
      console.info(this.industrydata);
      let data = this.industrydata;
      data = data.map((item) => {
        return {
          id: item.id,
          parent_id: item.parent_id,
          label: item.name,
        };
      });
      this.optionsMechanism = this.deleteChildren(this.getTrees(data));
      console.log("list => " + JSON.stringify(this.optionsMechanism));
    },
  }
};
</script>
<style scoped>
.search-condition-div {
  
}
.search-condition-div span {
  margin-left: 1px;
  cursor: pointer;
  border-radius: 5px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
  padding-bottom: 10px;
}
.follow-up-status-all {
  margin-left: 5px;
  background-color: #fff2ea;
  color: #FC8352;
}
.active {
    background-color: #fff2ea;
    color: #FC8352;
  }
</style>
